/* 
   Calculate the completeness for RA and DEC points. Output results
   to standard input

   ./completeness < input > output

*/

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "mask.h"
#define pi 3.1415926535898
#define sqr(x) ((x)*(x))

main(int argc, char *argv[])
{

  int i,j,junki,ID ;
  double junkf,RA,DEC,cz ;
  double theta,phi,x[3],comp;
  char *maskfile;

/*---Read-Arguments---------------------------------------------------*/

  if (argc < 1) 
    {
      printf("-Syntax: ./comp maskfile < input file > output file\n");
      exit(1);
    }
  maskfile = argv[1];

/*---Load-Mask-Info---------------------------------------------------*/
  loadmask(maskfile) ;

/*---Read-Galaxy-file-------------------------------------------------*/

  i = 0 ;
  while(fscanf(stdin,"%d %d %d %f %f %f %f %f",&ID,&junki,&junki,&RA,&DEC,&cz,&junkf,&junkf)!=EOF)
    {
      fprintf(stderr,"Doing %d\n",ID) ;
      theta = (90-DEC)*pi/180.0 ;
      phi = RA*pi/180.0 ;

      x[0] = sin(theta)*cos(phi) ;
      x[1] = sin(theta)*sin(phi) ;
      x[2] = cos(theta) ;
 
      comp = completeness(x) ;

      fprintf(stdout,"%7d %10.6f %10.6f %8.2f %8.6f\n",ID,RA,DEC,cz,comp) ;
    }
}
